package com.util;

import java.util.ArrayList;
import java.util.List;

public class PageUtilSuper <x>{
    private int pgNumber;
    private int pgSize;
    private List<x> list;
    private int maxNumber;

    public PageUtilSuper(int pgSize, List<x> list) {
        this.pgSize = pgSize;
        this.list = list;
        this.maxNumber = list.size() % pgSize == 0 ? list.size() / pgSize: (list.size() / pgSize) + 1;
    }

    public List<x> getPgNumberThing(int pgNumber){
        List<x> newList = new ArrayList<>();
        if(pgNumber >= 1 && pgNumber <= maxNumber){
            for (int i = 0; i < list.size(); i++) {
                if(i >= (pgNumber - 1) * pgSize && i < (pgNumber - 1) * pgSize + pgSize){
                    newList.add(list.get(i));
                }
            }
        }
        return newList;
    }

    public boolean haveNext(int pgNumber){
        if(pgNumber >= maxNumber){
            return false;
        }else {
            return true;
        }
    }

    public boolean havePrev(int pgNumber){
        if(pgNumber <= 1){
            return false;
        }else {
            return true;
        }
    }



    public int getPgNumber() {
        return pgNumber;
    }

    public void setPgNumber(int pgNumber) {
        this.pgNumber = pgNumber;
    }

    public int getPgSize() {
        return pgSize;
    }

    public void setPgSize(int pgSize) {
        this.pgSize = pgSize;
    }

    public List<x> getList() {
        return list;
    }

    public void setList(List<x> list) {
        this.list = list;
    }

    public int getMaxNumber() {
        return maxNumber;
    }

    public void setMaxNumber(int maxNumber) {
        this.maxNumber = maxNumber;
    }
}
